package models;

import play.Logger;
import play.data.validation.Email;
import play.data.validation.Required;
import play.db.jpa.Model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import java.util.List;

/**
 * @author Javier Gutierrez <bichocj@gmail.com>
 */
@Entity(name = "person")
public class Person extends Model {


    @Required
    public String name;

    @Required
    public String surname;

    @Email
    @Required
    public String email;

    public String password;

    @Column(name = "active")
    public boolean isActive;

    @Column(name = "super_admin")
    public boolean isSuperAdmin;

    @OneToMany(mappedBy = "person")
    public List<PersonDocument> personDocuments;

    @OneToMany(mappedBy = "person")
    public List<PersonDetail> personDetails;

    public static Person findByUserAndPassword(String user, String password) {
        Logger.info("email :" + user + " pass: " + password);
        return find("byEmailAndPassword", user, password).first();
    }

    @Override
    public String toString() {
        return name + " " + surname;
    }
}
